import 'package:daoyi_ui_admin_getx/app/widgets/common_image_widget.dart';
import 'package:daoyi_ui_admin_getx/app/widgets/common_tag.dart';
import 'package:flutter/material.dart';

import 'open_source_list_item_data.dart';

class OpenSourceListItemWidget extends StatelessWidget {
  final OpenSourceListItemData data;

  const OpenSourceListItemWidget(this.data, {super.key});

  String formatNumber(int number) {
    if (number > 1000) {
      return '${(number / 1000).toStringAsFixed(1)}k';
    }
    return number.toString();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 120,
      margin: const EdgeInsets.only(
        bottom: 2,
      ),
      padding: const EdgeInsets.all(10),
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: Row(
        children: <Widget>[
          CommonImageWidget(
            data.imageUri,
            width: 132.5,
            height: 100,
          ),
          const SizedBox(width: 10),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  data.title,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                    fontWeight: FontWeight.w600,
                  ),
                ),
                Text(
                  data.subTitle,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
                Wrap(
                  children: data.tags
                      .map(
                        (item) => CommonTag.factory(item),
                  )
                      .toList(),
                ),
                Row(
                  children: [
                    const Icon(Icons.code, size: 16),
                    const SizedBox(
                      width: 5,
                    ),
                    Wrap(
                      children: data.lang
                          .map(
                            (item) => CommonTag.factory(item),
                          )
                          .toList(),
                    ),
                    const SizedBox(
                      width: 10,
                    ),
                    const Icon(Icons.window_outlined, size: 16),
                    const SizedBox(
                      width: 5,
                    ),
                    Wrap(
                      children: data.category
                          .map(
                            (item) => CommonTag.factory(item),
                          )
                          .toList(),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Row(
                      children: [
                        const Icon(
                          Icons.star_outline,
                          color: Colors.orange,
                          size: 16,
                        ),
                        Text(
                          formatNumber(data.star),
                          style: const TextStyle(
                            color: Colors.orange,
                          ),
                        ),
                      ],
                    ),
                    Text(data.date),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
